package day9;

import java.util.Arrays;

//目的:要求你需要通过函数式编程的方式
//来实现接口  是为了简化  类实现接口  和方法重写
//function test(){}
//const zhuce=function(){}
//const login= ()=>{}  他就是函数式编程
//java使用函数式编程:通过lambda表达式 （）->{}
@FunctionalInterface //是否是正确的函数式接口
public interface Function {
    void test1(int a);
    String sex = "男";
    public default void test2(){

    }
    public static void main(String[] args) {
        Function fun = new Function() {
            @Override
            public void test1(int a) {
                System.out.println(a+"测试");
            }
        };
        Function fun2 = (int a) -> {
            System.out.println(a+"测试代码");
        };
        fun2.test1(1000);
    }
}

@FunctionalInterface
interface Function2 {
    public int math(int a,int b);
    public static void main(String[] args) {
        Function2 fun = (int a, int b) -> {
            int c = a + b;
            System.out.println("结果:" + c);
            return c;
        };
        fun.math(10, 20);
        Function fun1 = a -> {
            System.out.println(a);
        };
        Function2 fun2 = (a, b) -> {
            return a + b;
        };
        Function fun3 = a-> System.out.println(a);
        Function2 fun4 = (a,b)-> a+b;


        Function3 fun5 = Arrays::toString;
        int[] nums = {1,2,3,4,5,6,7,8,9};
        System.out.println(fun5.XXX(nums));
        System.out.println(Arrays.toString(nums));

        Function4 fun6 = Arrays::binarySearch;
        int i=fun6.test(nums,21);
        System.out.println(i);
    }
}

interface Function3 {
    public String XXX(int[] a);
}
interface Function4 {
    public int test(int[] nums, int n);
}